package model

type User_message_info struct {
	Id        int64 `xorm:"'id'"`
	User_id   int64 `xorm:"INTEGER unique notnull 'user_id'"`
	Last_time int   `xorm:"INTEGER notnull 'last_time'"`
}

func (this *User_message_info) Set(uid int64, time int) (err error) {
	var s = &User_message_info{
		User_id:   uid,
		Last_time: time,
	}
	has, err := this.Has()
	if err != nil {
		return err
	}

	if has {
		_, err = engine.Where("user_id=?", uid).Update(s)
		return err
	}
	_, err = engine.Insert(s)
	return err
}
func (this *User_message_info) Has() (bool, error) {
	c, err := engine.Count(this)
	if c > 0 {
		return true, err
	} else {
		return false, err
	}
}
func (this *User_message_info) GetLastime(uid int64) (time int, err error) {
	var s = &User_message_info{
		User_id: uid,
	}
	has, err := s.Has()
	if err != nil {
		return 0, err
	}
	if !has {
		return 0, err
	}
	_, err = engine.Get(s)
	return s.Last_time, nil
}
